<template>
	<zh-form :transprent="true" v-model="form" inputAlign="right" :label-width="200" :margin="[0, 24]" :padding="[10,0]">
	
	<zh-card :width="620">
		<template v-slot:title>
			<view style="border-left: 10rpx solid #2f54eb;">
				<zh-text  :fontSize="36" class="text-weight-b pl-10" :label="form.aac003"></zh-text>
			</view >
		</template>
		<template v-slot:status>
			<tm-icon  :fontSize="42" :name="data.hiddenFlag?'tmicon-eye-slash':'tmicon-eye'" style="margin: 0 20rpx;" @tap="changeSensitive"></tm-icon>
		</template>
		<template v-slot:content>
			<zh-form-desc  field="aab004" placeholder="未获取到参保单位信息"  v-model="form.aab004" label="参保单位"   :transprent="true"></zh-form-desc>
			<zh-form-desc  field="aae140Name" placeholder="未获取到参保险种"  v-model="form.aae140Name" label="参保险种"   :transprent="true"></zh-form-desc>
			<zh-form-desc v-if="false"  field="aae030" placeholder="未获取到参保开始时间"  v-model="form.aae030" label="参保开始时间"   :transprent="true"></zh-form-desc>
			<zh-form-desc v-if="false" field="aae031" placeholder="未获取到参保结束时间"  v-model="form.aae031" label="参保结束时间"   :transprent="true"></zh-form-desc>
			<zh-form-desc v-if="false" field="aab301Name" placeholder="未获取到参保地"  v-model="form.aab301Name" label="参保地"   :transprent="true"></zh-form-desc>
			<zh-sheet v-if="form.aab301!=='330783'" :margin="[0, 20]" :round="3" :padding="[20,20]" color="deep-orange" text>
				<zh-text  style="text-indent: 2em;padding-top:10rpx" label="您的社保参保地不在东阳,不能以社保信息作为报名条件"></zh-text>
			</zh-sheet>
			<zh-form-item :margin="[0,0]"  label="参保状态" field="status" >
				<view style="width:100%" class="flex-row-center-end">
					<zh-tag  :shadow="0" :followTheme="false" :color="form.status==='3'?'red':(form.status==='1'?'green':'orange')" text size="n" :label="form.statusName">
					</zh-tag>
				</view>
			</zh-form-item>
			<zh-form-desc v-if="false"  field="updateTime" placeholder="空" v-model="form.updateTime" label="数据获取时间" :transprent="true"></zh-form-desc>
			<zh-sheet v-if="form.continuityFlag==='1'&&form.aae140==='110'" :margin="[0, 20]" :round="3" :padding="[20,20]" color="green" text>
				<zh-text label="当前时间连续6个月缴纳企业养老保险。"></zh-text>
			</zh-sheet>
			<zh-sheet v-if="form.continuityFlag!=='1'&&form.aae140==='110'" :margin="[0, 20]" :round="3" :padding="[20,20]" color="red" text>
				<zh-text label="截至当前时间您未连续6个月缴纳企业养老保险。"></zh-text>
			</zh-sheet>
		</template>
		<zh-message ref="messageRef" :duration="2000"></zh-message>
	</zh-card>
	</zh-form>
</template>

<script lang="ts" setup>
	import {ref, reactive, onMounted,computed,watch} from "vue";
	import { system ,user} from '@/store';
	import * as util from '@/tool/function/util'
	import * as dayjs from 'dayjs/esm/index'
	const DayJs = dayjs.default
	const props = defineProps({
		myCheckInfo: {
		  type: Object,
		  default: () => {},
		},
		//社保信息
		modelValue: {
		  type: Object,
		  default: () => {},
		},
		index:{
		  type: Number,
		  default: 0,
		}
	})
	
	let messageRef=ref()
	const elderFlag=computed(() => {return system.uiStyle==='elder'})
	let form=ref<any>(Object.assign({},props.modelValue))
	let oldForm=ref<any>(Object.assign({},props.modelValue))
	// 主数据
	const data = reactive({
		//脱敏
		hiddenFlag:true,
		
	})
	const changeSensitive=()=>{
		data.hiddenFlag=!data.hiddenFlag
		enInfo()
	}
	const enInfo=()=>{
		if(data.hiddenFlag){
			form.value.aac003=getEnName(form.value.aac003);
			form.value.aac147=getEnIdcard(form.value.aac147);
		}else{
			form.value.aac003=oldForm.value.aac003;
			form.value.aac147=oldForm.value.aac147;
		}
	}
	//姓名加密
	const getEnName=(fullName:any)=>{
		if(!fullName){
			return '';
		}
		return '*'+fullName.substring(1,fullName.length)
	}
	//身份证加密
	const getEnIdcard=(idCard:any)=>{
		if(!idCard){
			return '';
		}
		let enCard = ""
		if (idCard.length===18) {
			enCard = idCard.replace(/(\w{1})\w*(\w{1})/, '$1****************$2');
		}else{
			let len=idCard.length/3
			let baseLen=idCard.length-len*2
			enCard=idCard.substring(0, len)
					
			for(var i=0;i<baseLen;i++){
				enCard=enCard+"*"
			}
			enCard=enCard+idCard.substring(len*2, idCard.length)
		}
		return enCard
	}
	const gotoAppeal=(type:String)=>{
		//前往社保信息申诉
		$router.push('/pages/edu/appeal/appeal', {type:type,id:form.value.socialSecurityId});
	}
	//前往我的申诉
	const gotoMyAppeal=()=>{
		$router.replace('/pages/edu/appeal/myAppeal', {});
	}
	//获取大数据社保
	const getCbInfo=()=>{
		let idcard=user.userInfo?.idcard
		if(!idcard){
			idcard=oldForm.value.aac147
		}
		let sbcountMap=util.getCookie("getSbCount:"+idcard);
		let curData=DayJs(new Date()).format('YYYYMMDD');
		let flag=true;
		let count=1;
		if(sbcountMap){
			let json=JSON.parse(sbcountMap)
			count=json[curData]||1
			if(json[curData]&&Number(json[curData])>=1){
				flag=false;
				let messageData: any = {}
				messageData.model = 'warn'
				messageData.text = '今日社保信息获取已达上限，请明天再试！'
				messageRef.value.show(messageData)
				return
			}
		}
		if(flag){
			$api.common.send.post("EduSocialSecurity0008", {idcard:(user.userInfo?.idcard)?'':idcard},null,true).then((res: any) => {
				let map={curData:count+1}
				util.setCookie("getSbCount:"+idcard,map);
				 if(res.result&&res.result.length>0){
					emits("refresh");
					let messageData: any = {}
					messageData.model = 'success'
					messageData.text = '获取成功！'
					messageRef.value.show(messageData)
				 }else{
					 let messageData: any = {}
					 messageData.model = 'warn'
					 messageData.text = '未获取到您在东阳的养老参保数据'
					 messageRef.value.show(messageData)
				 }
				 
			}).catch(()=>{
			})
		}
	}
	const emits = defineEmits([
	  "refresh",
	]);
	// 初始化
	onMounted(() => {
		enInfo()
	})
	watch(
	  () => props.modelValue,
	  () => {
	    form.value=Object.assign({},props.modelValue)
	    oldForm.value=Object.assign({},props.modelValue)
		enInfo()
	  },
	  { deep: true }
	);
</script>

<style>
</style>